package com.tmeone.erpone.controller;

import com.tmeone.erpone.entity.JsonResult;
import com.tmeone.erpone.entity.TMoveWarehouse;
import com.tmeone.erpone.service.TMoveWarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.UUID;

@RestController
public class TMoveWarehouseController {
    @Autowired
    TMoveWarehouseService moveWarehouseService;

    /**
     * 查询所有移库记录
     * 带分页
     * 作者：wzs
     * @param current 分页，当前页
     * @param size 分页，每页行数
     * @return 移库记录
     */
    @GetMapping("/mv")
    public JsonResult moveWarehouses(@RequestParam(value = "current",required = false,defaultValue = "1") long current,
                                     @RequestParam(value = "size",required = false,defaultValue = "5") long size) {
        return new JsonResult(1,moveWarehouseService.selectAll(current,size));
    }

    /**
     * 移库
     * 作者: wzs
     * @param moveWarehouse 移库记录
     * @return 响应信息
     */
    @PostMapping("/mv")
    public JsonResult transfer(@RequestBody TMoveWarehouse moveWarehouse) {
        moveWarehouse.setMvNo(String.valueOf(Math.floor(Math.random() * (9999999 - 1111111 + 1) + 1111111)));
        moveWarehouse.setId(UUID.randomUUID().toString().replace("-","").substring(0,10));
        moveWarehouse.setMvTime(new Date());
        moveWarehouseService.save(moveWarehouse);
        return new JsonResult(1,null);
    }
}
